<!--
 * @Description: 推进
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-07-06 19:18:59
 * @FilePath: /yuxiuproweb/src/views/mes/pro/workorder/advance/index.vue
-->
<template>
  <el-dialog
    :close-on-click-modal="false"
    v-dialogDrag
    title="订单推进"
    :visible.sync="shows"
    width="600px"
    append-to-body
  >
    <el-steps :active="active" finish-status="success" align-center>
      <el-step
        v-for="(item, index) in dict.type.pro_order_state"
        :key="item.value"
        :title="item.label"
        :description="
          index < active ? '已完成' : active === index ? '当前状态' : '未完成'
        "
      ></el-step>
    </el-steps>
    <el-divider content-position="center"></el-divider>
    <div class="h-formItem" v-if="[2].includes(active)">
      <span class="h-label">抹零:</span>
      <el-input-number
        v-model="pocketMoney"
        placeholder="请输入抹零金额"
        clearable
        :min="0"
        :precision="2"
      ></el-input-number>
    </div>
    <div
      class="h-formItem"
      v-if="data.isUsingRebate == 1 && [2].includes(active)"
    >
      <span class="h-label">返利金:</span>
      <!-- <el-input v-model="flmoney" placeholder="0.00" /> -->
      <el-input-number
        v-model="flmoney"
        placeholder="0.00"
        clearable
        :min="0"
        :precision="2"
      ></el-input-number>
    </div>

    <div class="h-formItem" v-if="[2].includes(active)">
      <span class="h-label">财务备注:</span>
      <el-input
        v-model="financialNotes"
        placeholder="请输入备注"
        type="textarea"
        :rows="2"
      />
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        @click="submitForm(active - 1)"
        v-if="[1, 2].includes(active)"
        >回 退</el-button
      >
      <el-button
        type="success"
        @click="submitForm(active + 1)"
        v-if="active !== 4"
        >推 进</el-button
      >
      <el-button @click="shows = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { auditOrder } from "@/api/asc/order";
export default {
  dicts: ["pro_order_state"],
  props: {
    show: Boolean,
    type: {
      type: String,
      default: "add",
    },
    data: {
      type: Object,
    },
  },
  data() {
    return {
      flmoney: 0.0,
      active: 0,
      money: 0.0,
      financialNotes: "",
      pocketMoney: 0,
      isButtonClicked: false,
    };
  },
  computed: {
    shows: {
      get() {
        return this.show;
      },
      set(newValue) {
        this.$emit("update:show", newValue);
      },
    },
  },
  created() {
    this.active = +this.data.state || 0;
  },
  methods: {
    /** 保存按钮 */
    async submitForm(state) {
      if (this.isButtonClicked) {
        return;
      }
      this.isButtonClicked = true;
      if (state == 3) {
        this.flmoney = this.flmoney;
      } else {
        this.flmoney = 0;
        this.pocketMoney = 0;
        this.financialNotes = "";
      }
      try {
        auditOrder({
          orderId: this.data.proOrderId,
          rebateAmount: this.flmoney,
          pocketMoney: this.pocketMoney,
          financialNotes: this.financialNotes,
          state,
        }).then(() => {
          this.$modal.msgSuccess("操作成功");
          this.shows = false;
          this.$emit("update");
        });
      } catch (e) {
        console.log(e);
      }
      setTimeout(() => {
        this.isButtonClicked = false;
      }, 1000);
    },
  },
};
</script>
<style lang="scss" scoped>
.h-formItem {
  display: flex;
  margin: 10px 20px;
  align-items: center;
  .h-label {
    width: 80px;
    text-align: center;
  }
}
</style>
